import {Clazz} from "./Clazz";
import * as THREE from 'three';

import Stats from 'three/examples/jsm/libs/stats.module.js';
import {GUI} from 'three/examples/jsm/libs/lil-gui.module.min.js';

import {GLTFLoader} from 'three/examples/jsm/loaders/GLTFLoader.js';

class Bird extends Clazz {
    constructor(scene) {
        super();
        this.clock = new THREE.Clock();
        this.loader = new GLTFLoader();
        this.mixers = [];
        const _this = this;
        this.loader.load('../js/components/images/bird/Flamingo.glb', function (gltf) {

            const mesh = gltf.scene.children[0];

            const s = 1;
            mesh.scale.set(s, s, s);
            mesh.position.y = 150;
            mesh.rotation.y = -0.5* Math.PI;

            mesh.castShadow = true;
            mesh.receiveShadow = true;

            scene.add(mesh);

            const mixer = new THREE.AnimationMixer(mesh);
            mixer.clipAction(gltf.animations[0]).setDuration(1).play();
            _this.mixers.push(mixer);

        });
    }

    update() {
        super.update();
        const delta = this.clock.getDelta();

        for (let i = 0; i < this.mixers.length; i++) {

            this.mixers[i].update(delta);

        }
    }
}

export {Bird}